<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
String path = request.getContextPath(); 
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<jsp:useBean id="user" class="com.hebxy.ssm.entity.User" scope="request"></jsp:useBean>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>套餐更新</title>
    <script>
        function confirmUpdate(plan_id) {
            if (confirm("确定要更新套餐吗？")) {
                document.getElementById("plan_id").value = plan_id;
                document.getElementById("updateForm").submit();
            }
        }
        
        // 显示操作结果消息
        window.onload = function() {
            const msg = '${result}';
            if (msg) {
                alert(msg);
            }
        };
    </script>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 20px;
            padding: 20px;
            background-color: #f5f5f5;
        }
        
        .container {
            max-width: 600px;
            margin: 0 auto;
        }
        
        h2 {
            color: #333;
            text-align: center;
            margin-bottom: 30px;
        }
        
        .plan-option {
            margin: 15px 0;
            padding: 10px;
            border-radius: 4px;
            background-color: white;
            box-shadow: 0 2px 4px rgba(0,0,0,0.1);
            cursor: pointer;
        }
        
        .plan-option:hover {
            box-shadow: 0 4px 8px rgba(0,0,0,0.1);
        }
        
        .current-plan {
            background-color: #e6e6e6;
            border-color: #4b4b4b;
            margin-top: 20px;
        }
        
        .update-btn {
            margin-left: 10px;
            padding: 5px 10px;
            cursor: pointer;
            background-color: #4CAF50;
            color: white;
            border: none;
            border-radius: 3px;
        }
        
        .update-btn:hover {
            background-color: #45a049;
            transform: translateY(-2px);
        }
        
        .current-plan.active {
            display: flex;
            align-items: center;
            gap: 15px;
        }
        
        input[type="hidden"] {
            opacity: 0.7;
            cursor: pointer;
        }
    </style>
</head>
<body>
    <div class="container">
        <h2>套餐更新</h2>
        
        <p>当前卡号: ${cardNumber}</p>
        
        <c:if test="${not empty currentPlan}">
            <p>当前套餐ID: ${currentPlan}</p>
        </c:if>

        <form id="updateForm" action="${pageContext.request.contextPath}/user/updatePlan" method="post">
            <input type="hidden" id="plan_id" name="plan_id" value="">

            <div class="plan-option ${currentPlan == 1 ? 'current-plan' : ''}">
                <span>套餐1</span>
                <button type="button" class="update-btn" onclick="confirmUpdate(1)">选择</button>
            </div>

            <div class="plan-option ${currentPlan == 2 ? 'current-plan' : ''}">
                <span>套餐2</span>
                <button type="button" class="update-btn" onclick="confirmUpdate(2)">选择</button>
            </div>

            <div class="plan-option ${currentPlan == 3 ? 'current-plan' : ''} active">
                <span>套餐3</span>
                <button type="button" class="update-btn" onclick="confirmUpdate(3)">选择</button>
            </div>
        </form>
    </div>

    <p style="margin-top:20px;">操作结果：${result}</p>
</body>
</html>
